import java.awt.event.*;
import java.io.*;

import javax.swing.*;

public class HandleListener implements ActionListener {
	JTextArea inputText, showText;

	public void setInputText(JTextArea text) {
		inputText = text;
	}

	public void setShowText(JTextArea text) {
		showText = text;
	}

	public void actionPerformed(ActionEvent e) {
		String str = e.getActionCommand();

		if (str.equals("copy"))
			showText.copy();
		else if (str.equals("cut"))
			showText.cut();
		else if (str.equals("paste"))
			inputText.paste();
		else if (str.equals("sava")) {
			File fWrite = new File("TXT//english.txt");
			try {
				Writer out = new FileWriter(fWrite);
				BufferedWriter bufferWrite = new BufferedWriter(out);
				bufferWrite.write(inputText.getText());
				bufferWrite.newLine();
				bufferWrite.close();
				out.close();
				JOptionPane.showMessageDialog(showText, "保存成功", "提示", JOptionPane.WARNING_MESSAGE);
			} catch (IOException e1) {
				System.out.println(e1.toString());
			}
		} else if (str.equals("open")) {
			File fRead = new File("TXT//english.txt");
			try {
				Reader in = new FileReader(fRead);
				BufferedReader bufferRead = new BufferedReader(in);
				String s = null;
				while ((s = bufferRead.readLine()) != null)
					showText.append(s + "\n");
				bufferRead.close();
				in.close();

			} catch (IOException e1) {
				System.out.println(e.toString());
			}
		} else if (str.equals("change")) {
			String old = JOptionPane.showInputDialog("输入要替换的值");
			String news = JOptionPane.showInputDialog("替换为");
			showText.setText(showText.getText().replaceAll(old, news));

		}
	}
}